package cn.wsalix.admin.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import cn.anlaser.repository.CommonRepository;
import cn.wsalix.admin.entity.AuthData;
import cn.wsalix.admin.entity.MenuPath;

public interface MenuPathRepository extends
		CommonRepository<MenuPath> {

	@Query("select rrr.AuthData from MenuPath rrr,UserRole ur where rrr.role.id =ur.postFix.id and ur.preFix.id=:userId")
	public List<AuthData> findRolesByUserId(@Param("userId") Long userId);

	@Modifying
	@Transactional
	@Query("delete from MenuPath rrr where rrr.role.id = :roleId")
	public void deleteByRoleId(@Param("roleId") Long roleId);

	@Modifying
	@Transactional
	@Query("delete from MenuPath rrr where rrr.role.id = :roleId and rrr.AuthData.id = :rrId")
	public void deleteByRR(@Param("roleId") Long roleId,
			@Param("rrId") Long rrId);
}
